/**
 * 
 */
package hr.fer.zemris.annotator.factories;

import java.util.ArrayList;
import java.util.List;

import hr.fer.zemris.annotator.model.Method;
import hr.fer.zemris.annotator.model.interfaces.IMethodFactory;
import hr.fer.zemris.annotator.model.profiling.FlatProfileData;

/**
 * @author dajan
 * 
 */
public class MethodFactory implements IMethodFactory {

	private static IMethodFactory instance = null;

	public static IMethodFactory getInstance() {
		if (instance == null) {
			instance = new MethodFactory();
		}
		return instance;
	}

	public Method getFlatMethodData(String line) {

		Method method = new Method();
		FlatProfileData profileData = new FlatProfileData();

		String[] lineSplit = line.split(" ");
		List<String> methodData = new ArrayList<String>();

		for (int i = 0, j = 0; i < lineSplit.length; i++) {
			if (!lineSplit[i].equals("")) {
				methodData.add(lineSplit[i]);
			}
		}

		profileData.setTimePercentage(methodData.get(0));
		profileData.setCumulativeSeconds(methodData.get(1));
		profileData.setSelfSeconds(methodData.get(2));
		profileData.setCalls(methodData.get(3));
		profileData.setSelfCalls(methodData.get(4));
		profileData.setTotalCalls(methodData.get(5));

		method.setMethodName(methodData.get(6));
		method.setProfileData(profileData);

		return method;
	}

	// public Method getGraphMethodData(Method method, String line) {
	// return null;
	// }

}
